package intensivecomp.mapred;

import intensivecomp.util.CustomerNLineInputFormat;
import intensivecomp.util.CustomerWholeFileInputFormat;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class DistanceCalculation {
    public static void main(String[] args) throws Exception{
        try {
            //config配置
            Configuration conf = new Configuration();
//            conf.set("mapred.remote.os","Linux");
            //conf.set("mapreduce.input.lineinputformat.linespermap","2");
            conf.set("mapreduce.jobtracker.split.metainfo.maxsize","-1");
//            conf.set("yarn.resourcemanager.address","master:8032");
//            conf.set("mapreduce.framework.name","yarn");
//            conf.set("mapreduce.job.jar","D:\\workspace\\Hadoop\\hadoop\\out\\artifacts\\distance_jar\\hadoop.jar");
//            conf.set("mapreduce.app-submission.cross-platform","true");
//            conf.set("fs.defaultFS", "hdfs://master:9000");
            //配置作业属性以及各个类
            Job job = Job.getInstance(conf);
            job.setJobName("Distance Calculation");
            job.setInputFormatClass(CustomerWholeFileInputFormat.class);
            job.setJarByClass(DistanceCalculation.class);
            job.setMapperClass(Map.class);
            job.setCombinerClass(Reduce.class);
            job.setReducerClass(Reduce.class);
            job.setOutputKeyClass(Text.class);
            job.setOutputValueClass(DoubleWritable.class);
            //设置输入输出格式
            CustomerWholeFileInputFormat.setInputDirRecursive(job, true);
            CustomerWholeFileInputFormat.addInputPath(job, new Path("hdfs://master:9000/tmp/data"));
            FileOutputFormat.setOutputPath(job, new Path("hdfs://master:9000/tmp/result"));
            //等待完成
            System.exit(job.waitForCompletion(true) ? 0 : 1);
        }
        catch (Exception e){
            e.printStackTrace();
        }

    }

}
